package com.sailfish.springbootdemo.dao.db5;

import com.sailfish.springbootdemo.common.DB5TableName;
import com.sailfish.springbootdemo.pojo.db5.EmpTPublicStaff;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface EmpTPublicStaffDao {

    @Select("<script>" +
            "select * from " + DB5TableName.EMP_T_PUBLIC_STAFF + " where 1 = 1 " +
            "<if test='searchName != null and searchName != \"\" '>" +
            " and (preferred_name like CONCAT('%',#{searchName},'%') or emp_name like CONCAT('%',#{searchName},'%') or display_name like CONCAT('%',#{searchName},'%') or domain_account like CONCAT('%',#{searchName},'%') or dept1_name like CONCAT('%',#{searchName},'%') or dept2_name like CONCAT('%',#{searchName},'%') or dept3_name like CONCAT('%',#{searchName},'%') or dept4_name like CONCAT('%',#{searchName},'%'))" +
            "</if>" +
            "</script>")
    @Results(id = "empTPublicStaffResultMap", value = {
            @Result(column = "emp_type", property = "empType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "emp_code", property = "empCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "emp_name", property = "empName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "english_name", property = "englishName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "display_name", property = "displayName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "preferred_name", property = "preferredName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sex", property = "sex", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept1_code", property = "dept1Code", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept1_name", property = "dept1Name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept2_code", property = "dept2Code", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept2_name", property = "dept2Name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept3_code", property = "dept3Code", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept3_name", property = "dept3Name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept4_code", property = "dept4Code", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept4_name", property = "dept4Name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_code", property = "deptCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "coa", property = "coa", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dept_name", property = "deptName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "email", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "domain_account", property = "domainAccount", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notes_id", property = "notesId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "tel_long_num", property = "telLongNum", jdbcType = JdbcType.VARCHAR),
            @Result(column = "tel_short_num", property = "telShortNum", jdbcType = JdbcType.VARCHAR),
            @Result(column = "site", property = "site", jdbcType = JdbcType.VARCHAR),
            @Result(column = "entry_date", property = "entryDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "position_name", property = "positionName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "cn_display_name", property = "cnDisplayName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "placeof_performance_ctid", property = "placeofPerformanceCtid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "placeof_performance_ctname", property = "placeofPerformanceCtname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "placeof_assignment_ctid", property = "placeofAssignmentCtid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "placeof_assignment_ctname", property = "placeofAssignmentCtname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "director", property = "director", jdbcType = JdbcType.VARCHAR),
            @Result(column = "director_code", property = "directorCode", jdbcType = JdbcType.VARCHAR),
    })
    List<EmpTPublicStaff> getAllEmpTPublicStaff(@Param("searchName") String searchName);

    @ResultMap(value = "empTPublicStaffResultMap")
    @Select("select * from " + DB5TableName.EMP_T_PUBLIC_STAFF + " where domain_account = #{domainAccount} limit 1")
    EmpTPublicStaff getEmpTPublicStaffByDomainAccount(@Param("domainAccount") String domainAccount);
}
